//模块化，这个js文件只写计算相关的vuex代码
export default {
  namespaced: true,
  state: {
    sum: 0,
    school: '尚硅谷',
    subject: '前端',
  },
  actions: {
    addOdd(context, value) {
      if (context.state.sum % 2) {
        context.commit('ADDODD', value);
      }
    },
    addWait(context, value) {
      setTimeout(() => {
        context.commit('ADDWAIT', value);
      }, 500);
    },
  },
  mutations: {
    ADD(state, value) {
      // console.log(store, value);
      state.sum += value;
    },
    REDUCE(state, value) {
      // console.log(store, value);
      state.sum -= value;
    },
    ADDODD(state, value) {
      state.sum += value;
    },
    ADDWAIT(state, value) {
      state.sum += value;
    },
  },
  getters: {
    bigSum(state) {
      return state.sum * 10;
    },
  },
};
